//index.js
//获取应用实例
const app = getApp()
const qcloud = require('../../bower_components/wafer-client-sdk/index.js')
const api = require('../../utils/api.js')

Page({
  data: {
    motto: 'Hello World',
    userInfo:{}
  },
  //事件处理函数
  scanTap: function() {
    wx.scanCode({
      success: function(res){
        console.log(res)
        var params = res.result.split('#')
        // var params = [1,201]
        console.log(params)
        wx.navigateTo({
          url: '../dish/dish?rid='+params[0]+'&tid='+params[1],
        })
      },
      fail: function() {
        console.log('failed')
      },
      complete: function() {
        // complete
      }
    })
  },
  onLoad: function () {
    var that = this
    qcloud.setLoginUrl(api.url.login); 
    qcloud.request({
      login: true,
      url: api.url.user,
      success: function (response) {
        console.log(response);
        that.setData({
          userInfo:response.data
        })
        wx.setStorage({
          key: 'openId',
          data: response.data.openId
        })
      },
      fail: function (err) {
         console.log(err);
      }
    });
  },
  recordTap:function(){
    wx.navigateTo({
      url: '../record/record'
    })
  }
 
})
